﻿using TjZheng.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using TjZheng.Framework;

namespace TjZheng.EasyUI
{
    public static partial class QueryExtension
    {
        public static MvcHtmlString QueryDateTimeBox(this HtmlHelper htmlHelper, string title, string name, QueryMethod objQueryMethod, QueryDataType objQueryDataType, object htmlAttributes = null, params string[] validTypes)
        {
            IDictionary<string, object> objHtmlAttributes = htmlAttributes.CreateValueDictionary();
            if (objHtmlAttributes.IsNull())
            {
                objHtmlAttributes = new Dictionary<string, object>();
            }
            List<string> dataOptionsList = new List<string>();
            if (validTypes.IsNoNull())
            {
                dataOptionsList.Add(string.Format("validType:[{0}]", validTypes.JoinComma()));
            }
            object data = null;
            if (objHtmlAttributes.TryGetValue("dataoptions", out data))
            {
                if (data.ToString().IsNoNull())
                {
                    dataOptionsList.Add(data.ToString());
                }
                objHtmlAttributes.Remove("dataoptions");
            }
            dataOptionsList.Add("formatter:FormatDate");
            //dataOptions["parser"] = "ParserDate";
            objHtmlAttributes["data-options"] = dataOptionsList.JoinComma();
            QueryTextBox objQueryTextBox = new QueryTextBox(name, QueryBoxType.DateTimeBox)
            {
                QueryTitle = title,
                QueryMethod = objQueryMethod,
                QueryDataType = objQueryDataType,
                HtmlAttributes = objHtmlAttributes
            };
            return htmlHelper.CreateQueryInfo(objQueryTextBox);
        }
        public static MvcHtmlString QueryDateTimeBox(this HtmlHelper htmlHelper, string title, string name, object htmlAttributes = null, params string[] validTypes)
        {
            return htmlHelper.QueryDateTimeBox(title, name, QueryMethod.GreaterEqual, QueryDataType.DateTime, htmlAttributes, validTypes);
        }
    }
}
